package com.wulian.common.context;

import java.util.HashMap;
import java.util.Map;

import com.wulian.common.constants.CommonConstants;


/**
 * 
* @ClassName: BaseContextHandler 
* @Description: TODO(获取上下文) 
* @author 马志豪
* @date 2019年9月11日 下午5:04:40 
*
 */
public class BaseContextHandler {
    public static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>();

    public static void set(String key, Object value) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        map.put(key, value);
    }

    public static Object get(String key) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        return map.get(key);
    }

    public static Object getUserInfo() {
        return get(CommonConstants.USER_INFO);
    }

    public static void setUserInfo(Object value) {
        set(CommonConstants.USER_INFO, value);
    }

    public static void remove() {
        threadLocal.remove();
    }

}
